﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using HZ.Supervise.Model;

namespace HZ.Supervise.Web.PageControl
{
    public partial class CompanyLeft : BasePage
    {
        string strhid = "";
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //add by 曹鹏 2011年5月7日15:42:29 取得当前用户
                lblCurrentUser.Text = HZ.Supervise.Web.Function.GetNowTime() + "&nbsp;&nbsp;<img alt='' src='../Images/ModalImageAh_New/smile.gif'/>&nbsp;&nbsp;" + CurrentAccount.GetUser().UserName;
                //取得当前用户角色
                this.lblCurrentRole.Text = CurrentAccount.GetUser().Org.OrgName;
      
                ViewState["query"] = URLUtil.GetSuperviseQueryFromURL(Request);
            
                
                bangdingCompany();           
            }
        }

        protected void gvwselect_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                string sessionid = Guid.NewGuid().ToString();
                SuperviseQuery query = new SuperviseQuery();
                query.CompanyName_PS = e.Row.Cells[0].Text.Trim();
                if (rblcompanytype.SelectedValue == "0")
                {
                    query.CompanyType = 0;
                }
                else
                {
                    query.CompanyType = 2;
                }
                Session[sessionid] = query;


                e.Row.Cells[0].Text = "<a  style=\"cursor:hand\" onclick=\"seturl('" + sessionid + "')\">" + e.Row.Cells[0].Text + "</a>";

            }

        }


        /// <summary>
        /// 绑定企业
        /// </summary>
        private void bangdingCompany()
        {

            HZ.Supervise.IBLL.IBLL_PreWarning pre = HZ.Supervise.BLLFactory.IBLL_PreWarning();
            string _CompanyID = DAL.DAL_Helper.Replace(txtname.Text.Trim());
            if (_CompanyID.Equals(""))
            {
                _CompanyID = "所有企业";
            }
       
            int totalrecord = 0;
            DataTable dt = pre.GetCompanyName(_CompanyID, rblcompanytype.SelectedValue, AspNetPager1.CurrentPageIndex, AspNetPager1.PageSize, out totalrecord);
            AspNetPager1.RecordCount = totalrecord;
            gvwselect.DataSource = dt;
            gvwselect.DataBind();
            if (dt.Rows.Count==0)
            {
                Label1.Text = "暂无符合条件的数据";
            }
            
        }

        /// <summary>
        /// 查询
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnQuery_Click(object sender, EventArgs e)
        {
            this.AspNetPager1.CurrentPageIndex = 1;
        }

        protected void rblcompanytype_SelectedIndexChanged(object sender, EventArgs e)
        {
            bangdingCompany();

			string sessionid = Guid.NewGuid().ToString();

			SuperviseQuery query = new SuperviseQuery();

			if (rblcompanytype.SelectedValue == "0")
			{
				query.CompanyType = 0;
			}
			else
			{
				query.CompanyType = 2;
			}

			Session[sessionid] = query;

			ClientScript.RegisterStartupScript(this.GetType(), "CallFunc", "<script> seturl('" + sessionid + "')</script>");
        }

        protected void AspNetPager1_PageChanged(object sender, EventArgs e)
        {
            bangdingCompany();
        }

        protected void btnQuery_Click(object sender, ImageClickEventArgs e)
        {
            AspNetPager1.CurrentPageIndex = 1;
        }

        protected void gvwselect_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
               // e.Row.Attributes.Add("onclick", "c=this.style.backgroundColor; this.style.backgroundColor='#CCCCCC'");
                //变量c用与存储鼠标移动在行上时，原来的背景色，然后设置为'#CCCCCC'
                e.Row.Attributes.Add("onclick", "a(this);");
                //当鼠标离开时，还原背景色
            }

        }
    }
}
